#include<bits/stdc++.h>

using namespace std;

const int N=110;

string m,day;
set<string> s;

int month[]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int a[N]={ 0,3,8 ,5, 1 ,6 ,3, 4 ,6 ,7, 0, 7 ,8 ,2, 7, 6 ,8 ,9 ,5 ,6 ,5 ,6, 1 ,4 ,0 ,1,
0, 0, 9 ,4 ,8 ,0 ,9 ,1 ,2, 8, 5 ,0 ,2 ,5 ,3 ,3};//41

void check()
{
	int t1=stoi(m);
	if(t1<1||t1>12) return;
	int t2=stoi(day);
	if(t2<1||t2>month[t1]) return;
	string t=m+day;
	s.insert(t);
}

int main()
{
	int n=41;
	for(int i=1;i<=n-3;i++)
	for(int j=i+1;j<=n-2;j++)
	for(int c=j+1;c<=n-1;c++)
	for(int d=c+1;d<=n;d++)
	{
		m="";day="";
		m.push_back(a[i]+'0');
		m.push_back(a[j]+'0');
		day.push_back(a[c]+'0');
		day.push_back(a[d]+'0');
		check();
	}
	
	cout<<s.size()<<endl;
	return 0;
} 
